package com.viewonimage.ta.lab;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

public class CustomImageView extends ImageView {

	Bitmap listbm[] = null;
	private int index;
	
	private boolean checkruntext;
	private int counttime=100;
	
	
	
	public boolean isCheckruntext() {
		return checkruntext;
	}

	public void setCheckruntext(boolean checkruntext) {
		this.checkruntext = checkruntext;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public Bitmap[] getListbm() {
		return listbm;
	}
	

	public void setListbm(Bitmap[] listbm) {
		this.listbm = listbm;
	}

	public CustomImageView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	
	
	public CustomImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}



	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawBitmap(listbm[index], 0, 0, null);
		
		if(checkruntext==true&&(counttime>=0)){
		Paint a = new Paint();
			a.setColor(Color.BLUE);
			canvas.drawText("Time: " + counttime--, 20, 20, a);
		}
	}



	public void getArrayImage(AnimationDrawable background) {
		// TODO Auto-generated method stub
		int totalFram = background.getNumberOfFrames();
		Log.i("TA", "Total fram : "+totalFram);
		for(int i = 0 ; i<totalFram ; i++){
			if(listbm == null){
				listbm = new Bitmap[totalFram];
			}
			Log.i("TA", listbm[i]+" item");
			listbm[i] = ((BitmapDrawable)background.getFrame(i)).getBitmap();
			Log.i("TA", listbm[i]+" item-------");
		}
	}

	
	
	
}
